Add method='datashader' to render_images for sparse images#676
Open
timtreis wants to merge 6 commits into
Open
Add method='datashader' to render_images for sparse images#676timtreis wants to merge 6 commits into
timtreis wants to merge 6 commits into
Conversation
Mean-aggregating rasterization + imshow interpolation collapses very
sparse images (mostly zeros, rare non-zero pixels) to near-black.
Adds method='datashader' + ds_reduction kwargs mirroring the existing
render_points/render_shapes API; routes the downsample step through
datashader.Canvas.raster with a configurable reduction (default 'max')
and forces nearest-neighbor display so the reduction is not re-smoothed.
Also centralizes the _DsReduction Literal (previously duplicated across
five sites) into render_params.py alongside a new _ImageDsReduction for
the image-only set ('mode', 'first', 'last' added; 'sum', 'any', 'count'
dropped since they're not valid Canvas.raster downsample methods).
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #676 +/- ##
==========================================
+ Coverage 77.72% 77.90% +0.17%
==========================================
Files 11 11
Lines 3641 3679 +38
Branches 860 868 +8
==========================================
+ Hits 2830 2866 +36
- Misses 486 487 +1
- Partials 325 326 +1
🚀 New features to boost your workflow:
|
Five test_plot_* methods covering the high-signal cases for #449: hero sparse-pixel test (default vs datashader=max side-by-side), ds_reduction grid (max/min/mean/mode), multi-channel with per-channel cmap, transfunc+cmap composition, and shapes-on-top composition. Reference PNGs to be sourced from the next CI artifact run.
Drop the standalone TestRenderImagesDatashaderVisual class and its sparse-data helper; add two test_plot_* methods directly to TestImages. Keeps the two high-signal cases (hero side-by-side + reduction grid) and drops the multichannel-cmap, transfunc, and shapes-overlay panels whose code paths are already locked by non-visual tests.
- Rename render_images public kwarg ds_reduction -> datashader_reduction to match the existing render_points/render_shapes API; ImageRenderParams field name stays (matches the points/shapes internal field name). - Bind get_args(_ImageDsReduction) once in the validation block. - Mark the spatialdata.rasterize geometry-only call as a TODO for a future cheaper path. - Redesign the reduction-grid visual test: mid-grey background + sparse bright pixels so max/min/mean/mode produce visibly distinct panels instead of nearly-identical stripes. Reference PNG to be regenerated from the next CI artifact run.
Member
Author
|
FYI @LucaMarconato |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
method='datashader'andds_reductionkwargs torender_images()so very sparse images (mostly zeros, rare non-zero pixels) survive the downsample step instead of being averaged to near-black by the default mean-aggregating rasterization +imshowinterpolation. Mirrors the existingrender_points/render_shapesAPI.datashader.Canvas.rasterwith a configurable downsample method (default'max'); forcesimshow(interpolation='nearest')on that path so the chosen reduction isn't re-smoothed at display time. Geometry + spatial transformations are inherited fromspatialdata.rasterizeso the output integrates cleanly with the existing transform plumbing._DsReduction(previously inline-duplicated across 5 sites) intorender_params.py, alongside a new_ImageDsReductionfor the image-only valid set (mode,first,lastadded;sum,any,countremoved since they're not validCanvas.rasterdownsample_methodvalues).API addition (purely additive, defaults preserve current behavior)
method=None(default) is byte-for-byte identical to the existing path.